package hu.genius.view;

import hu.genius.R;
import hu.genius.R.layout;
import hu.genius.model.entity.Product;
import hu.genius.view.adapters.ProductItemAdapter;
import hu.genius.view.utils.ActionsUtils;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

public class ActionsListActivity extends ListActivity {
	String actionUrl = "http://www.donpedropizza.hu/html/androidAction.php";
	private List<Product> products;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actions);
		
		products = ActionsUtils.listActions();
		
		this.setListAdapter(new ProductItemAdapter(this,
				R.layout.listview_product_item_layout, products));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Product product = products.get(position);

		Intent intent = new Intent(this, SelectProduct.class);
		intent.putExtra("product_id", product.getId());
		intent.putExtra("product_category_id", product.getCategoryId());
		intent.putExtra("product_name", product.getName());
		intent.putExtra("product_price", product.getPrice());
		intent.putExtra("image", product.getImage());
		
		Log.d("zs", "selected product: (" + product + ")");
		this.startActivity(intent);
	}

	public void back(View view) {
		this.finish();
	}

}